<template>
  <bm-overlay
    ref="customOverlay"
    :class="{sample: true, active}"
    pane="labelPane"
    @draw="draw">
    <div v-text="address" @click="handleClick"></div>
    <div v-text="count" @click="handleClick"></div>
  </bm-overlay>
</template>

<script>
  export default {
    props: ['address', 'position', 'active','count'],
    watch: {
      position: {
        handler () {
          this.$refs.customOverlay.reload()
        },
        deep: true
      }
    },
    methods: {
      handleClick () {
        global.alert('房源数量')
      },
      draw ({el, BMap, map}) {
        const {lng, lat} = this.position
        const pixel = map.pointToOverlayPixel(new BMap.Point(lng, lat))
        el.style.left = pixel.x - 60 + 'px'
        el.style.top = pixel.y - 20 + 'px'
      }
    }
  }
</script>

<style>
  .sample {
    width: 100px;
    height: 100px;
    line-height: 40px;
    border-radius: 50%;
    background: rgba(0, 102, 204,0.9);
    overflow: hidden;
    box-shadow: 0 0 5px #000;
    color: #fff;
    text-align: center;
    padding: 10px;
    position: absolute;
  }
  .sample.active {
    background: rgba(0,0,0,0.75);
    color: #fff;
  }
</style>
